<?php namespace Common\Model;
use Hdphp\Model\Model;
use Common\Model\Order_list;
class Orders extends Model{
	protected $table = 'orders';
	//	自动验证
    protected $validate = [
        ['name','required','购车人必填',3,3],
        ['address','required','提车城市必填',3,3],
        ['mobile','required','手机号必填',3,3],
        ['mobile','_mobile','手机号填写错误，用于接收购车凭证，请确保准确',3,3],

    ];
	public function store(){
		if(!$this->create()) return FALSE;
		$this->data['address']=implode('|', $this->data['address']);
		$this->data['number']=time().rand(1, 999);
		$this->data['uid']=$_SESSION['uid'];
		$this->data['time']=time();
		$this->data['total']=$_SESSION['cart']['total'];
//		p($this->data);
//		exit;
       $oid=$this->add();
		$orderListModel=new Order_list;
			$orderListModel->create();
			foreach($_SESSION['cart']['goods'] as $v){
			$orderListModel->data['quantity']=$v['num'];
			$orderListModel->data['subtotal']=$v['total'];
			$orderListModel->data['sid']=$v['id'];
			$orderListModel->data['oid']=$oid;
//			$orderListModel->data['slid']=$v['options']['slid'];
			$orderListModel->data['glnumber']=rand(1, 999).time();
			$orderListModel->data['shuxing']=implode('|',$v['options']['attribute']);
			$orderListModel->add();
		}
		
		return TRUE;

	}
	
    
	public function _mobile(){
		$mobile=Q('post.mobile');
		if(!preg_match("/^1[34578]\d{9}$/", $mobile)){
			return false; 
		}
		return true;      
        
    } 
	
	
}